package com.example.demo.main;

import com.example.demo.util.ExportUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @Classname testExportUtil
 * @Description 导出excle类
 * @Date 2019/8/12 10:48
 * @Created by yby
 */
public class testExportUtil {

   /* public static void main(String[] args) {
        //获取数据
        List<CpUser> list =new ArrayList<>();
        *//*CpUser c1=new CpUser();
        c1.setUname("王一");
        c1.setSex("男");
        c1.setAge(18);
        c1.setBusinessName("沙县小吃");
        CpUser c2=new CpUser();
        c2.setUname("王二");
        c2.setSex("女");
        c2.setAge(28);
        c2.setBusinessName("肯德基");
        CpUser c3=new CpUser();
        c3.setUname("王三");
        c3.setSex("男");
        c3.setAge(38);
        c3.setBusinessName("鲜丰水果");
        list.add(c1);
        list.add(c2);
        list.add(c3);*//*

        for(int i=0;i<15;i++){
            CpUser c1=new CpUser();
            c1.setUname("网易");
            c1.setSex("男");
            c1.setAge(18+i);
            c1.setBusinessName("沙县小吃");
            list.add(c1);
        }


        //excel标题
        String[] title = {"名称","性别","年龄","门店"};

         //excel文件名
        String fileName = "用户信息表"+System.currentTimeMillis()+".xls";

        //sheet名
        String sheetName = "用户信息表";
        String[][] content = new String[list.size()][];

        for (int i = 0; i < list.size(); i++) {
            content[i] = new String[title.length];
            CpUser obj = list.get(i);
            content[i][0] = obj.getUname();
            content[i][1] = obj.getSex();
            content[i][2] = String.valueOf(obj.getAge());
            content[i][3] = obj.getBusinessName();
         }


        //创建HSSFWorkbook
        HSSFWorkbook wb = ExportUtil.getHSSFWorkbook(sheetName, title, content, null);

        //响应到客户端
        try {
            //this.setResponseHeader(response, fileName);
           //OutputStream os = response.getOutputStream();
           //wb.write(os);
           //os.flush();
           //os.close();
            //java相应 就ok
            FileOutputStream out =  new FileOutputStream("D:\\新森\\Excle\\test1.xls");
            wb.write(out);
            out.flush();
            out.close();
         } catch (Exception e) {
               e.printStackTrace();
        }
    }*/

    public static void main(String[] args) {
        System.out.println("1111122121");
        System.out.println(System.currentTimeMillis()/1000);
    }
}
